﻿using RayDen.RayEngine.Core.Interface;

namespace RayDen.RayEngine.Samplers
{
    public class SamplerFactory
    {
        protected static readonly SamplerFactory instance = new SamplerFactory();

        public static SamplerFactory Instance
        {
            get { return instance; }
        }

        protected IImageFilm film;

        public void SetFilm(IImageFilm f)
        {
            this.film = f;
        }

        public ISampler CreateSampler(int w, int h, int maxDepth, int yStart, bool lowLatency, int threadIndex, int windowHeight)
        {
            switch (GlobalConfiguration.Instance.SamplerType)
            {                   
                case 1:
                    return new LDSampler() { screenWidth = w, screenHeight = h, lowLatency = true, screenStartLine = yStart + 1, tIdx = threadIndex };
                case 2:
                    return new PPRandomSampler { screenWidth = w, screenHeight = h, lowLatency = true, screenStartLine = yStart + 1, tIdx = threadIndex };

                case 3:
                    return new AdaptiveBlockSampler() { screenWidth = w, screenHeight = h, lowLatency = true, screenStartLine = yStart + 1, tIdx = threadIndex, Film = this.film as AdaptiveImageFilm };

                case 4:
                    return new DadeUniformSampler(){ screenWidth = w, screenHeight = h, lowLatency = true, screenStartLine = yStart + 1, tIdx = threadIndex };

                default:
                    return new RandomSampler() { screenWidth = w, screenHeight = h, lowLatency = true, screenStartLine = yStart + 1, tIdx = threadIndex };
            }
            //return new PhotonMappingContextSampler() { screenWidth = w, screenHeight = h, lowLatency = lowLatency, screenStartLine = yStart, tIdx = threadIndex };
            //return new PSSMLTSampler() { screenWidth = w, screenHeight = h, lowLatency = true, screenStartLine = yStart+1, tIdx = threadIndex};
            //return new DadeUniformSampler() { screenWidth = w, screenHeight = h, lowLatency = true, screenStartLine = yStart + 1, tIdx = threadIndex };
            //return new RandomSampler() { screenWidth = w, screenHeight = h, lowLatency = true, screenStartLine = yStart+1, tIdx = threadIndex};
            //return new PPRandomSampler { screenWidth = w, screenHeight = h, lowLatency = true, screenStartLine = yStart+1, tIdx = threadIndex};

            //return new AdaptiveBlockSampler() { screenWidth = w, screenHeight = h, lowLatency = true, screenStartLine = yStart + 1, tIdx = threadIndex, Film = this.film as AdaptiveImageFilm };
        }


        public string GetSamplerType()
        {
            return this.CreateSampler(0, 0, 0, 1, false, 0, 0).GetType().Name;
        }
    }
}